/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cassys.dataaccess.hibernate;

import cassys.dataaccess.DAOException;
import cassys.dataaccess.TeamDAO;
import cassys.datatransferobjects.TeamDTO;
import cassys.exceptions.HibernateAccessLayerException;
import java.util.ArrayList;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Priyanka
 */
public class TeamDAOImpl extends AbstractDao implements TeamDAO {

    @Override
    public void deleteTeam(TeamDTO dto) throws HibernateAccessLayerException{
       try {
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Deleting Team" + dto.getTeamId() );
            super.delete(dto);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public TeamDTO findTeam(String teamid) throws HibernateAccessLayerException{
          try {
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Finding Team" + teamid);
            TeamDTO p = (TeamDTO) super.find(TeamDTO.class, teamid);
            return p;
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public ArrayList<TeamDTO> findAllTeam() throws HibernateAccessLayerException{
        try {
            return (ArrayList<TeamDTO>) super.findAll(TeamDTO.class);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
    }

    @Override
    public void updateTeam(TeamDTO dto) throws HibernateAccessLayerException{
        try {
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Updating Team" + dto.getTeamId()); 
            super.saveOrUpdate(dto);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
    }

    @Override
    public void insertTeam(TeamDTO dto) throws HibernateAccessLayerException{
        try {
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Inserting Team" + dto.getTeamId()); 
            super.saveOrUpdate(dto);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
    }

    @Override
    public ArrayList<TeamDTO> findAllTeamByModule(String moduleCode) throws DAOException {
         try {
            return (ArrayList<TeamDTO>) super.findAllByParam(TeamDTO.class, "moduleCode", moduleCode);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
    }
    
}
